import $app from '../$app';

let zL_do={
	//专利提交 type //1发明专利,2实用新型,3外观专利
	patentDoSub(type, that) {


		let {
			order_id, //订单ID，首次提交为空；有订单ID，就是修改订单；
			goods_id,
			zName1: name,
			attorney_path: {
				file_path: attorney_path,
				file_path1: attorney_path1
			},
			attorney_name_list
		} = that.$refs['baseTop'];

		//基本信息 判断专用
		if (!$app.pBaseTop_judge(that, name, attorney_path)) return;


		/////////////////////////// 分割线 ///////////////////////////

		let {
			applicant_list, //申请人信息
			inventor_list//发明人
		} = that.$refs['common'];

		//申请人判断专用
		if (!$app.pCom_judge(that, applicant_list, inventor_list)) return;

		applicant_list = JSON.stringify(applicant_list);
		// console.log('申请人列表json串 = ', applicant_list);

		inventor_list = JSON.stringify(inventor_list);
		// console.log('发明人列表json串 = ',inventor_list);



		//////////////////////////////// 分割线，申请的核心资料 ////////////////////////////////

		let patent_file_path,
			instruction_path,
			instruction_abstract_path,
			claims_path,
			instruction_image_path,
			abstract_image_path,
			is_cost_reduction,
			same_day,
			is_early_release,
			abstract_image_index,
			claims_item_count,
			appe_img_list = '', //外观专利图片1和2的时候为空；1发明专利,2实用新型,3外观专利
			appe_brief_desc_path,
			wgImg;

		if (type == 3) { //外观

			({
				patent_file_path,

				is_cost_reduction,
				same_day,
				is_early_release,
				abstract_image_index,
				claims_item_count,

				five_books: {
					instruction_path: {
						file_path: instruction_path
					},
					instruction_abstract_path: {
						file_path: instruction_abstract_path
					},
					claims_path: {
						file_path: claims_path
					},
					instruction_image_path: {
						file_path: instruction_image_path
					},
					abstract_image_path: {
						file_path: abstract_image_path
					},
				},
				appe_img_list: wgImg,
				appe_brief_desc_path: {
					file_path: appe_brief_desc_path
				}
			} = that);

			appe_img_list = []; //外观专利变成数组，方便push操作
			wgImg.forEach((val, i) => {
				appe_img_list.push($app.getVal_filePath(val));
			});
			appe_img_list = JSON.stringify(appe_img_list);

		} else { //发明+实用新型
			({
				patent_file_path,

				is_cost_reduction,
				same_day,
				is_early_release,
				abstract_image_index,
				claims_item_count,

				five_books: {
					instruction_path: {
						file_path: instruction_path
					},
					instruction_abstract_path: {
						file_path: instruction_abstract_path
					},
					claims_path: {
						file_path: claims_path
					},
					instruction_image_path: {
						file_path: instruction_image_path
					},
					abstract_image_path: {
						file_path: abstract_image_path
					},
				},
				appe_img_list,
				appe_brief_desc_path
			} = that.$refs['middle']);

		}


		//////////////////////////////// 分割线，申请的核心资料 ////////////////////////////////





		//优先权声明- 必填选填 校验
		if (!$app.p_d_l_judge(that.$refs['other'].$refs['PDList'])) return;

		//优先权声明
		let {
			priority_declar_list
		} = that.$refs['other'].$refs['PDList'];
		priority_declar_list = ($app.judgeData(priority_declar_list) ? JSON.stringify(priority_declar_list) : '');


		let preserve_data = ''; //生物材料样本-只有发明专利有

		let {
			other_tool_show, //手风琴框
			main_applicant,

			//不丧失新颖性宽限期声明
			other_one,
			other_two,
			other_three,

			preserve_is_dna,
			preserve_is_genetic,
			similar_design,
			complete_product
		} = that.$refs['other'];

		// 分案申请 判断
		if (!$app.fenAn_jud(that.$refs['other'])) return;
		let {
			//分案申请
			div_app_number, //原申请号
			div_app_date, //原申请日期
			case_div_app_number, //针对的分案申请号
		} = that.$refs['other'];






		//专利提交 type //1发明专利,2实用新型,3外观专利
		if (type == 1) { //生物材料样本-只有发明专利有=>做特殊判断
			let dTt = that.$refs['other'].preserve_data.preserve_date;

			if (dTt && (typeof dTt === 'object')) { //DatePicker 先天性的bug =》再处理
				that.$refs['other'].preserve_data.preserve_date = ($app.formatTime(2, ((dTt).valueOf() / 1000)))
			}


			let {
				preserve_data: {
					preserve_unit_code, // 保藏单位代码,
					preserve_address, // 保藏地址,
					preserve_date, // 日期 2019-7-24,
					preserve_number, // 保藏编号,
					preserve_type_name, // 分类命名,
				}
			} = that.$refs['other'];


			let jutTTg = $app.delSpace(preserve_unit_code) ||
				$app.delSpace(preserve_address) ||
				$app.delSpace(preserve_date) ||
				$app.delSpace(preserve_number) ||
				$app.delSpace(preserve_type_name);

			// 任何一个，删除空格 =》 有值都可以，
			if (jutTTg) {
				preserve_data = JSON.stringify(that.$refs['other'].preserve_data); //生物材料样本
			}


		}


		let obj = {
			order_id: order_id,
			type,

			//baseTop
			name,
			goods_id,
			attorney_path, //委托书文件路径
			attorney_path1, //已经批了章

			attorney_name_list,

			//common
			applicant_list, //申请人列表json串
			inventor_list, //发明人列表json串

			//中间
			patent_file_path, //专利文件 - 五书合一
			instruction_path, //五书 - 说明书
			instruction_abstract_path, //五书 - 说明书摘要
			claims_path, //五书 - 权利要求书
			instruction_image_path, //五书 - 说明书附图
			abstract_image_path, //五书 - 摘要附图
			is_cost_reduction,
			same_day,
			is_early_release,
			abstract_image_index,
			claims_item_count,
			appe_img_list,
			appe_brief_desc_path,


			//其他
			priority_declar_list, //优先权声明
			preserve_data, //生物材料样本-只有发明专利有，其他都为空
			other_tool_show, //手风琴框
			main_applicant,
			div_app_number,
			div_app_date,
			case_div_app_number,

			//不丧失新颖性宽限期声明
			other_one,
			other_two,
			other_three,

			preserve_is_dna,
			preserve_is_genetic,
			similar_design,
			complete_product
		};

		// console.log('go = ',obj)
		console.log('专利提交，上传字段 = ', $app.objToArray(1, obj), '\n', obj);

		zL_do.gweJu['type' + type](that, obj); //各种类型提交的判断

	},
	//各种类型提交的判断 配合上者使用
	gweJu: {
		shu(obj, callBack) {
			if (!$app.judgeData(obj.instruction_path)) {
				$app.alert('说明书，不能为空', '申请材料（五书）');
			} else if (!$app.judgeData(obj.instruction_abstract_path)) {
				$app.alert('说明书摘要，不能为空', '申请材料（五书）');
			} else if (!$app.judgeData(obj.claims_path)) {
				$app.alert('权利要求书，不能为空', '申请材料（五书）');
			} else {
				callBack();
			}
		},
		//1发明专利
		type1(that, obj) {
			this.shu(obj, () => {
				if ($app.judgeData(obj.instruction_image_path) && !$app.numPlus(obj.abstract_image_index)) {
					that.$Message.error({
						content: '请输入指定说明书附图中的图数字，勿含空格等特殊字符'
					});
					that.$refs['middle'].$refs['abstract_image_index'].focus(); //聚焦
				} else if (!$app.numPlus(obj.claims_item_count)) {
					that.$Message.error({
						content: '请输入权利要求的项数，勿含空格等特殊字符'
					});
					that.$refs['middle'].$refs['claims_item_count'].focus(); //聚焦
				} else {
					$app.gweQRT(that, obj); //恭喜发财提交
				}
			});
		},
		//2实用新型
		type2(that, obj) {
			this.shu(obj, () => {
				if (!$app.judgeData(obj.instruction_image_path)) {
					$app.alert('说明书附图，不能为空', '申请材料（五书）');
				} else if (!$app.judgeData(obj.abstract_image_path)) {
					$app.alert('摘要附图，不能为空', '申请材料（五书）');
				} else if (!$app.numPlus(obj.claims_item_count)) {
					that.$Message.error({
						content: '请输入权利要求的项数，勿含空格等特殊字符'
					});
					that.$refs['middle'].$refs['claims_item_count'].focus(); //聚焦
				} else {
					$app.gweQRT(that, obj); //恭喜发财提交
				}
			});
		},
		//3外观专利
		type3(that, obj) {
			let {
				appe_img_list,
				appe_brief_desc_path
			} = that;
			if (!$app.judgeData(appe_img_list)) {
				$app.alert('外观设计图片，不能为空', '温馨提示');
			} else if (!$app.judgeData(appe_brief_desc_path)) {
				$app.alert('外观简要说明书，不能为空', '温馨提示');
			} else {
				$app.gweQRT(that, obj); //恭喜发财提交
			}
		},
	},
};

export default zL_do;
